/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-19
 * Time: 00:56
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Threading;

using Labb4.Entity;
using Labb4.Pooman.Misc;
using Labb4.Pooman.Game;
using Labb4.Pooman.Cards;
using Labb4.Rules;

namespace Labb4.Pooman.Players
{
	/// <summary>
	/// A control for controling players of the game Pooman.
	/// These controls are not added in the ControlManager.
	/// </summary>
	public abstract class PoomanControl : Control
	{
		#region members
		
		/// <summary>
		/// The player controlled by this controler
		/// </summary>
		protected Player			m_Player;
		/// <summary>
		/// The state of the button "Play Cards"
		/// </summary>
		protected bool				m_PressedPlay;
		/// <summary>
		/// The state of the button "Chance"
		/// </summary>
		protected bool				m_PressedChance;
		/// <summary>
		/// The state of the button "Pick up Cards"
		/// </summary>
		protected bool				m_PressedPickup;
		/// <summary>
		/// If the phase has ended this should be set to true
		/// </summary>
		protected bool				m_CurrentPhaseIsOver;
		/// <summary>
		/// Reference to the input manager
		/// </summary>
		protected InputManager		m_InputManager;
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, initializes members
		/// </summary>
		public PoomanControl() :
			base()
		{
			m_Player = null;
			m_PressedPlay = false;
			m_PressedChance = false;
			m_PressedPickup = false;
			m_CurrentPhaseIsOver = false;
			m_InputManager = InputManager.Instance;
		}
		
		#endregion
		
		#region virtuals
		
		/// <summary>
		/// Base for selecting cards, checks if the player still has cards on the current hand
		/// </summary>
		public virtual void SelectCards()
		{
			if(m_Player.CurrentHand.Cards.Count == 0)
			{
				//something has ended..
				m_CurrentPhaseIsOver = true;
			}
		}
		
		/// <summary>
		/// The display type of this player, ai's override this with a call to the properties class
		/// </summary>
		/// <returns>Display type of this player as a string</returns>
		public virtual string DisplayType()
		{
			return "normal";
		}
		
		#endregion
		
		#region abstracts
		
		/// <summary>
		/// Evaluates the won cards based on what type of player this is. The ai players use
		/// their different approaches to evaluate the cards. The player playing the game
		/// is treated as a value-ai since this is the most direct and graphical way of
		/// evaluating cards
		/// </summary>
		/// <param name="cards">The cards to evaluate</param>
		/// <returns>The result of the evaluation as an enum defined in Player</returns>
		public abstract Player.Evaluation EvaluateWonCards(CardPile cards);
		
		#endregion
		
		#region properties
		
		/// <summary>
		/// Reference to the player this control controls (set/get)
		/// </summary>
		public Player ControlledPlayer
		{
			get
			{
				return m_Player;
			}
			
			set
			{
				m_Player = value;
			}
		}
		
		/// <summary>
		/// The state of the button "Play Cards" (set/get)
		/// 
		/// Is always set to false when read, meaning it can only be true once per click
		/// </summary>
		public bool PressedPlay
		{
			get
			{
				bool play = m_PressedPlay;
				m_PressedPlay = false;
				return play;
			}
			
			set
			{
				m_PressedPlay = value;
			}
		}
		
		/// <summary>
		/// The state of the button "Chance" (set/get)
		/// 
		/// Is always set to false when read, meaning it can only be true once per click
		/// </summary>
		public bool PressedChance
		{
			get
			{
				bool chance = m_PressedChance;
				m_PressedChance = false;
				return chance;
			}
			
			set
			{
				m_PressedChance = value;
			}
		}
		
		/// <summary>
		/// The state of the button "Pick up Cards" (set/get)
		/// 
		/// Is always set to false when read, meaning it can only be true once per click
		/// </summary>
		public bool PressedPickup
		{
			get
			{
				bool pickup = m_PressedPickup;
				m_PressedPickup = false;
				return pickup;
			}
			
			set
			{
				m_PressedPickup = value;
			}
		}
		
		#endregion
	}
}
